import { createRouter, createWebHistory } from 'vue-router'
import { ElMessage } from 'element-plus'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/Login.vue')
    },{
      path: '/findPassword',
      name: 'findPassword',
      component: () => import('../views/FindPassword.vue')
    },{
      path:'/',
      name:'home',
      component: () => import('../views/Home.vue')
    }
  ]
})


// 导航守卫
router.beforeEach((to, from, next) => {
  // let isLogin = false
  const token = localStorage.getItem('Authorization');
  if (token || to.path === '/login' || to.path === '/findPassword') {
    next()
  } else {
    ElMessage.warning('您还未登录哦')
    router.push('/login')
  }
})

export default router
